<template>
  <div class="nav-menu">
    <div class="nav-menu__container">
      <div
        class="menu__item"
        v-for="item in navMenu"
        :key="item.id"
        :style="{
          width: `calc(70vw / ${navMenu.length} - 4vw)`,
          height: `calc(70vw / ${navMenu.length} - 4vw)`,
          backgroundColor: item.color
        }"
        @click="goPath(item)"
      >
        <img :src="setSrc(item.icon)" alt="" />
        {{ item.title }}
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { NavMenuItem, getMenu } from '@/config/navigationMenu'

defineOptions({
  name: 'Demo'
})

const router = useRouter()
const route = useRoute()

const navMenu = computed<NavMenuItem[]>(() => {
  return getMenu(Number(route.query.id))?.children || []
})

const goPath = (item: NavMenuItem) => {
  router.push(item.path)
}

// 引入图标
const setSrc = (name?: string) => {
  return new URL(`../../../assets/menuIcon/${name}.svg`, import.meta.url).href
}
</script>

<style lang="scss" scoped>
.nav-menu {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  &__container {
    display: flex;
    // flex-wrap: wrap;
  }
}

.menu__item {
  margin: 0 2vw;
  background-color: #248b5c;
  color: #ffffff;
  font-size: 42px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  max-width: 500px;
  max-height: 500px;
  img {
    width: 200px;
    height: 200px;
    margin-bottom: 40px;
  }
}
</style>
